package cn.iocoder.yudao.module.erp.enums;

import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

@Getter
public enum PurchaseTypeConstants {
    SERVICE("SERVICE", "服务"),
    EQUIPMENT("EQUIPMENT", "设备"),
    ENGINEERING("ENGINEERING", "工程"),
    MATERIAL("MATERIAL", "物资"),
    DIRECT("DIRECT", "小额直接采购"),
    MINOR("MINOR", "小额零星采购");

    private final String code;
    private final String description;

    PurchaseTypeConstants(String code, String description) {
        this.code = code;
        this.description = description;
    }

    // 如果需要，可以添加一个方法来根据code获取枚举实例
    public static PurchaseTypeConstants fromCode(String code) {
        for (PurchaseTypeConstants constant : PurchaseTypeConstants.values()) {
            if (constant.code.equals(code)) {
                return constant;
            }
        }
        throw new IllegalArgumentException("未知的采购类型代码: " + code);
    }

    public static PurchaseTypeConstants ofByCode(String code) {
        return Stream.of(values()).filter(it -> Objects.equals(it.getCode(), code)).findFirst()
                .orElseThrow(()->new RuntimeException(String.format("不支持采购类型%s",code)));
    }
}
